using System;
using Prometheus.TypeUtility;

namespace Prometheus.Binding.Validation.Rules.Simple
{
    /// <summary>
    /// Use it to validate data by handling ValidateBy event on the form
    /// Param1 is value, Param2 is DataContext
    /// </summary>
    public class jDelegateValidationRule : proValidationRuleBase
    {
        public event EventHandler<GenericEventArgs2<object, object>> ValidateBy;

        public void InvokeValidateBy(object parameter1, object parameter2)
        {
            EventHandler<GenericEventArgs2<object, object>> handler = ValidateBy;
            if (handler != null)
            {
                handler(this, new GenericEventArgs2<object, object>(parameter1, parameter2));
            }
            else
            {
                throw new NullReferenceException("You have to handle ValidateBy event");
            }
        }

        public override void Validate(object value, object dataContext)
        {
            InvokeValidateBy(value, dataContext);
        }
    }
}